﻿#ifndef SCREENSHOTOVERLAY__H
#define SCREENSHOTOVERLAY__H

#include <QWidget>
#include <QScreen>
#include <QPainter>
#include <QMouseEvent>
#include <QKeyEvent>
#include <QClipboard>
#include <QFileDialog>
#include <QMessageBox>
#include <QDateTime>
#include <QMenu>
#include <QAction>
#include <QSystemTrayIcon>
#include <QShortcut>
#include <QSettings>
#include <QApplication>
#include <QHBoxLayout>
#include <QPushButton>

class ScreenshotOverlay : public QWidget
{
    Q_OBJECT
public:
    explicit ScreenshotOverlay(QWidget *parent = nullptr);
    ~ScreenshotOverlay();
protected:
    void paintEvent(QPaintEvent *event) override;
    void mousePressEvent(QMouseEvent *event) override;
    void mouseMoveEvent(QMouseEvent *event) override;
    void mouseReleaseEvent(QMouseEvent *event) override;
    void keyPressEvent(QKeyEvent *event) override;
signals:
    void accepted(const QPixmap &screenshot);
    void cancelled();
    void saveRequested(const QPixmap &screenshot);

private:
    enum ResizeHandle {
        NoHandle,
        TopLeft, Top, TopRight,
        Left, Right,
        BottomLeft, Bottom, BottomRight
    };
    void setupButtons();
    void startNewSelection(const QPoint &pos);
    QPixmap getScreenshot() const;
    ResizeHandle getResizeHandle(const QPoint &pos) const;
    void updateCursor(ResizeHandle handle);
    void drawResizeHandles(QPainter &painter);
    void handleResize(const QPoint &pos);
private:
    QPixmap m_fullScreenshot;
    QPoint m_selectionStartPoint;
    QPoint m_selectionCurrentPoint;
    QPoint m_dragOffset;
    QPoint m_resizeStartPoint;
    QRect m_selectionRect;
    QRect m_resizeStartRect;
    bool m_isSelecting;
    bool m_isResizing;
    bool m_isDragging;
    ResizeHandle m_resizeHandle;
    QWidget *m_buttonWidget;
};

#endif // SCREENSHOTOVERLAY__H
